package com.sora.sora.security.authorise.service.impl;

import com.sora.sora.security.authorise.model.entity.Resources;
import com.sora.sora.security.authorise.mapper.ResourcesMapper;
import com.sora.sora.security.authorise.service.ResourcesService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import java.util.Set;

@Service("resourcesService")
public class ResourcesImpl implements ResourcesService {

    @Resource
    ResourcesMapper resourcesMapper;

    @Override
    public int delResourcesByType(int type) {
        return resourcesMapper.delResoucesByType(type);
    }

    @Override
    public int addResouces(Collection<Resources> resources) {
        if (resources.isEmpty()) {
            return -1;
        }
        return resourcesMapper.addResources(resources);
    }

    @Override
    public List<Resources> getResourcesByUserId(int userId) {
//        List<Resources> resources = resourcesMapper.queryResourcesByUserId(userId);
//        return resources;
        return resourcesMapper.queryResourcesByUserId(userId);
    }

    @Override
    public Set<Integer> getResourcesIdByUserId(int userId) {
        return resourcesMapper.queryIdByUserId(userId);
    }

    @Override
    public List<Resources> getPageResourcesByUserId(int uid) {
        return resourcesMapper.queryPageResourcesByUserId(uid);
    }
}
